package com.choosefine.it.team.service;

import com.choosefine.it.base.dto.PageDTO;
import com.choosefine.it.common.utils.DateUtils;
import com.choosefine.it.team.dao.TeamCooperateBusMapper;
import com.choosefine.it.team.model.TeamCooperateBus;
import com.choosefine.it.team.model.dto.TeamCooperateBusSaveDTO;
import com.choosefine.it.team.model.vo.TeamCooperateBusVO;
import com.choosefine.it.team.model.vo.TeamSupplierInfoVO;
import com.choosefine.it.team.model.vo.queryAffiliatedUnitsVO;
import com.choosefine.it.team.model.vo.queryTeamVO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Comments：班组合作商家相关 Author：maojun Create Date：2017/2/17 Modified By： Modified
 * Date： Why & What is modified： Version：v1.0
 */
@Service("teamCooperateBusService")
public class TeamCooperateBusService {
	@Autowired
	TeamCooperateBusMapper teamCooperateBusMapper;

	/**
	 * @Author maojun
	 * @Date 2017/2/17 15:36
	 */
	public Page<TeamCooperateBusVO> queryTeamCooperateBus(Map<String, Object> params, PageDTO pageDto) {
		PageHelper.startPage(pageDto.getPageNum(), pageDto.getPageSize());
		Page<TeamCooperateBusVO> list = teamCooperateBusMapper.queryTeamCooperateBus(params);
		return list;
	}

	/**
	 * @Author maojun
	 * @Date 2017/2/17 15:36
	 */
	public Page<TeamSupplierInfoVO> querySupplier(Map<String, Object> params, PageDTO pageDto) {
		PageHelper.startPage(pageDto.getPageNum(), pageDto.getPageSize());
		Page<TeamSupplierInfoVO> list = teamCooperateBusMapper.querySupplier(params);
		return list;
	}

	/**
	 * @Author maojun
	 * @Date 2017/2/17 15:36
	 */
	public int changePartnership(Map<String, Object> params) {
		return teamCooperateBusMapper.changePartnership(params);
	}

	/**
	 * @Author maojun
	 * @Date 2017/2/17 15:36
	 */
	public int saveTeamCooperateBus(List<TeamCooperateBusSaveDTO> list) {
		int count = 0;
		for (TeamCooperateBusSaveDTO teamCooperateBusSaveDTO : list) {
			TeamCooperateBus teamCooperateBus = new TeamCooperateBus();
			teamCooperateBus.setCompanyName(teamCooperateBusSaveDTO.getCompanyName());
			teamCooperateBus.setCompanyType(teamCooperateBusSaveDTO.getCompanyType());
			teamCooperateBus.setCorporation(teamCooperateBusSaveDTO.getCorporation());
			teamCooperateBus.setProjectCode(teamCooperateBusSaveDTO.getProjectCode());
			teamCooperateBus.setTenantRole(teamCooperateBusSaveDTO.getTenantRole());
			teamCooperateBus.setUserCode(teamCooperateBusSaveDTO.getUserCode());
			teamCooperateBus.setAffiliatedUnitId(teamCooperateBusSaveDTO.getAffiliatedUnitId());
			teamCooperateBus.setAffiliatedUnitName(teamCooperateBusSaveDTO.getAffiliatedUnitName());
			teamCooperateBus.setCtime(DateUtils.getNowTime());
			teamCooperateBusMapper.saveTeamCooperateBus(teamCooperateBus);
			count++;
		}
		return count;
	};

	/**
	 * @Author maojun
	 * @Date 2017/2/17 15:36
	 */
	public List<queryTeamVO> queryTeam(Map<String, Object> params) {
		return teamCooperateBusMapper.queryTeam(params);
	}

	public List<queryAffiliatedUnitsVO> queryAffiliatedUnits(Map<String, Object> params) {
		return teamCooperateBusMapper.queryAffiliatedUnits(params);
	}
}